﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace Generator.DBUtility
{
    public class MYSQLUtility 

    {
        public static DataSet GetTableNames(string ConnectStr)
        {
            List<string> tables = new List<string>();

            DataSet dtSet = new DataSet();
            using (MySqlConnection con = new MySqlConnection(ConnectStr))
            {
                MySqlCommand command = new MySqlCommand("show tables;", con);
                MySqlDataAdapter adapter = new MySqlDataAdapter(command);
                adapter.Fill(dtSet);
            }
            return dtSet;

            
        }

        public static DataSet GetTableFields(string ConnectStr,string tableName)
        {

            DataSet dtSet = new DataSet();
            using (MySqlConnection con = new MySqlConnection(ConnectStr))
            {
                MySqlCommand command = new MySqlCommand(string.Format("describe {0};", tableName), con);
                MySqlDataAdapter adapter = new MySqlDataAdapter(command);
                adapter.Fill(dtSet);
            }
            return dtSet;

           

        }     

    }
}
